﻿using System;
using System.Collections.Generic;

namespace LightController
{
    [Serializable]

    public class Light
    {
        private ILightController _LightController;
        private string _id;
        private LightChanel _LightChanel;
        private string _Chanel;
        private string _Name;
        private int _Value;
        private string _Description;
        private string _Type;

        public Light() { }
        public Light(Light light)
        {
            _LightController = light.LightController;
            Id = light.Id;
            Name = light.Name;
            Value = light.Value;
            Description = light.Description;
            Type = light.Type;
            _LightChanel = light.LightChanel;
            _Chanel = light.Chanel;
        }
        public ILightController LightController
        {
            get
            {
                return _LightController;
            }
            set
            {
                _LightController = value;
            }
        }
        public string Chanel
        {
            get
            {
                return _LightChanel.Name;
            }
        }
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }
        public string LightControllerName
        {
            get
            {
                return _LightController.Name;
            }
        }

        public int Value
        {
            get { return _Value; }
            set
            {
                _Value = value;
            }
        }
        public string Description
        {
            get { return _Description; }
            set
            {
                _Description = value;
            }
        }
        public string Type
        {
            get { return _Type; }
            set
            {
                _Type = value;
            }
        }

        public string Id
        {
            get
            {
                return _id;
            }

            set
            {
                _id = value;
            }
        }

        public LightChanel LightChanel
        {
            get
            {
                return _LightChanel;
            }

            set
            {
                _LightChanel = value;
            }
        }

        public bool ON()
        {
            if (_LightChanel == null)
            {
                return false;
            }
            return _LightController.SetIntensity(_LightChanel.No, _Value);
        }

        public bool ReadValue(ref int value)
        {
            if (_LightChanel == null)
            {
                return false;
            }
            return _LightController.ReadIntensity(_LightChanel.No, ref value);
        }

        public bool OFF()
        {
            if (_LightChanel == null)
            {
                return false;
            }
            return _LightController.SetIntensity(_LightChanel.No, 0);
        }

        public bool ON(List<Light> lights)
        {
            if (lights == null || lights.Count == 0)
            {
                return false;
            }
            List<int> chs = new List<int>();
            List<int> vals = new List<int>();
            foreach (var light in lights)
            {
                chs.Add(light.LightChanel.No);
                vals.Add(light.Value);
            }
            return _LightController.SetMultiIntensity(chs, vals);
        }

        public bool ON(List<Light> lights, string ProdcutAdress, string ProdcutName, int openCount)
        {
            if (lights == null || lights.Count == 0)
            {
                return false;
            }
            List<int> chs = new List<int>();
            List<int> vals = new List<int>();
            foreach (var light in lights)
            {
                chs.Add(light.LightChanel.No);
                vals.Add(light.Value);
            }
            return _LightController.SetMultiIntensity(chs, vals, ProdcutAdress, ProdcutName, openCount);
        }

        public bool OFF(List<Light> lights)
        {
            List<int> chs = new List<int>();
            List<int> vals = new List<int>();
            foreach (var light in lights)
            {
                chs.Add(light.LightChanel.No);
                vals.Add(0);
            }
            return _LightController.SetMultiIntensity(chs, vals);
        }
    }
}
